﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using WPFExcelReport;
using WPFExcelReport.Controls;
using WPFExcelReport.Helpers;
namespace INTEX.SCHEDULER
{
    /// <summary>
    /// Interaction logic for Machine.xaml
    /// </summary>
    /*
    public partial class JobBase : WPFExcelReport.ViewBase
    {
        #region ==IsABF===========
        public static readonly DependencyProperty IsABFProperty = DependencyProperty.Register("IsABF",
            typeof(bool), typeof(JobBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsABFChanged));
        public bool IsABF
        {
            get
            {
                return (bool)GetValue(IsABFProperty);
            }
            set
            {
                SetValue(IsABFProperty, value);
            }
        }
        private static void OnIsABFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.IsABF = (bool)e.NewValue;
                src.LOADABF();
            }
        }

        #endregion

        #region ==IsKSL===========
        public static readonly DependencyProperty IsKSLProperty = DependencyProperty.Register("IsKSL",
            typeof(bool), typeof(JobBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsKSLChanged));
        public bool IsKSL
        {
            get
            {
                return (bool)GetValue(IsKSLProperty);
            }
            set
            {
                SetValue(IsKSLProperty, value);
            }
        }
        private static void OnIsKSLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.IsKSL = (bool)e.NewValue;
                src.LOADKSL();
            }
        }

        #endregion

        #region ==ProductionType===========
        public static readonly DependencyProperty ProductionTypeProperty = DependencyProperty.Register("ProductionType",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnProductionTypeChanged));
        public string ProductionType
        {
            get
            {
                return (string)GetValue(ProductionTypeProperty);
            }
            set
            {
                SetValue(ProductionTypeProperty, value);
            }
        }
        private static void OnProductionTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.ProductionType = (string)e.NewValue;
            }
        }
        #endregion
 
        #region ==JobID===========
        public static readonly DependencyProperty JobIDProperty = DependencyProperty.Register("JobID",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJobIDChanged));
        public string JobID
        {
            get
            {
                return (string)GetValue(JobIDProperty);
            }
            set
            {
                SetValue(JobIDProperty, value);
            }
        }
        private static void OnJobIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.JobID = (string)e.NewValue;
            }
        }
        #endregion 

       

        #region ==AUF===========
        public static readonly DependencyProperty AUFProperty = DependencyProperty.Register("AUF",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFChanged));
        public string AUF
        {
            get
            {
                return (string)GetValue(AUFProperty);
            }
            set
            {
                SetValue(AUFProperty, value);
            }
        }
        private static void OnAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.AUF = (string)e.NewValue;
            }
        }
        #endregion

        #region ==JobType===========
        public static readonly DependencyProperty JobTypeProperty = DependencyProperty.Register("JobType",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJobTypeChanged));
        public string JobType
        {
            get
            {
                return (string)GetValue(JobTypeProperty);
            }
            set
            {
                SetValue(JobTypeProperty, value);
            }
        }
        private static void OnJobTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.JobType = (string)e.NewValue;
                src.SetJobTypeDes();
            }
        }
        #endregion

        #region ==JobDes===========
        public static readonly DependencyProperty JobDesProperty = DependencyProperty.Register("JobDes",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJobDesChanged));
        public string JobDes
        {
            get
            {
                return (string)GetValue(JobDesProperty);
            }
            set
            {
                SetValue(JobDesProperty, value);
            }
        }
        private static void OnJobDesChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.JobDes = (string)e.NewValue;
            }
        }
        #endregion

        #region ==JobTypeDes===========
        public static readonly DependencyProperty JobTypeDesProperty = DependencyProperty.Register("JobTypeDes",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJobTypeDesChanged));
        public string JobTypeDes
        {
            get
            {
                return (string)GetValue(JobTypeDesProperty);
            }
            set
            {
                SetValue(JobTypeDesProperty, value);
            }
        }
        private static void OnJobTypeDesChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.JobTypeDes = (string)e.NewValue;
            }
        }
        #endregion

        #region ==JobQty===========
        public static readonly DependencyProperty JobQtyProperty = DependencyProperty.Register("JobQty",
            typeof(double), typeof(JobBase),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJobQtyChanged));
        public double JobQty
        {
            get
            {
                return (double)GetValue(JobQtyProperty);
            }
            set
            {
                SetValue(JobQtyProperty, value);
            }
        }
        private static void OnJobQtyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.JobQty = (double)e.NewValue;
            }
        }
        #endregion

        #region ==MachineID===========
        public static readonly DependencyProperty MachineIDProperty = DependencyProperty.Register("MachineID",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMachineIDChanged));
        public string MachineID
        {
            get
            {
                return (string)GetValue(MachineIDProperty);
            }
            set
            {
                SetValue(MachineIDProperty, value);
            }
        }
        private static void OnMachineIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.MachineID = (string)e.NewValue;
            }
        }
        #endregion

        #region ==ABFBLFDNR===========
        public static readonly DependencyProperty ABFBLFDNRProperty = DependencyProperty.Register("ABFBLFDNR",
            typeof(string), typeof(JobBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnABFBLFDNRChanged));
        public string ABFBLFDNR
        {
            get
            {
                return (string)GetValue(ABFBLFDNRProperty);
            }
            set
            {
                SetValue(ABFBLFDNRProperty, value);
            }
        }
        private static void OnABFBLFDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.ABFBLFDNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==AWIDTH===========
        public static readonly DependencyProperty AWIDTHProperty = DependencyProperty.Register("AWIDTH",
            typeof(double), typeof(JobBase),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAWIDTHChanged));
        public double AWIDTH
        {
            get
            {
                return (double)GetValue(AWIDTHProperty);
            }
            set
            {
                SetValue(AWIDTHProperty, value);
            }
        }
        private static void OnAWIDTHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JobBase;
            if (src != null)
            {
                src.AWIDTH = (double)e.NewValue;
            }
        }
        #endregion

        private DateTime _CalendarStart;
        public DateTime CalendarStart
        {
            get
            {
                return MCALENDAR.CalendarStart;
            }
            set            
            {
                _CalendarStart = value;
            }
    
        }

        public MCALENDAR MCALENDAR
        {
            get;
            set;
        }

        public void SetJobTypeDes()
        {
            switch (JobType)
            {
                case "P":
                    JobTypeDes = "生产";
                    break;
                case "S":
                    JobTypeDes = "自排";
                    break;
                case "C":
                    JobTypeDes = "确认";
                    break;
                case "X":
                    JobTypeDes = "日历";
                    break;
            }

        }

        public NameScope PageScope
        {
            get;
            set;
        }

        public DataTable ABFOLGE
        {
            get;
            set;
        }
      
        Grid StepShow
        {
            get
            {
                return this.FindName("Steps") as Grid;
            }
        }

        public MGANTT MGANTT
        {
            get
            {
                return Machine.MGANTT;
            }
        }

        private UIAM machine;
        public UIAM Machine
        {
            get
            {
                return machine;
            }
            set
            {
                machine = value;
                if (value != null)
                {
                   // MachineID = value.MachineID;
                }
            }
        }

        public DateTime StartDate = new DateTime();
        public DateTime EndDate = new DateTime();

        public DataTable KSLEIST
        {
            get;
            set;
        }

        public DataRow dwJob
        {
            get;
            set;
        }

        public DataRow dwMask
        {
            get;
            set;
        }

        public int MinPixes = 0;
        private double _NMQTYPLAN; public double NMQTYPLAN { get { return _NMQTYPLAN; } set { _NMQTYPLAN = value; } }
        private double _MQTYPLAN; public double MQTYPLAN { get { return _MQTYPLAN; } set { _MQTYPLAN = value; } }
        private double _NMQTYBOOK; public double NMQTYBOOK { get { return _NMQTYBOOK; } set { _NMQTYBOOK = value; } }
        private double _MQTYBOOK; public double MQTYBOOK { get { return _MQTYBOOK; } set { _MQTYBOOK = value; } }
        private double _MQTYUSED; public double MQTYUSED { get { return Helper.RoundX(_MQTYUSED, 1); } set { _MQTYUSED = value; } }
        private double _QTYACT; public double QTYACT { get { return _QTYACT; } set { _QTYACT = value; } }
        private double _NPQTYPLAN; public double NPQTYPLAN { get { return _NPQTYPLAN; } set { _NPQTYPLAN = value; } }
        private double _PQTYPLAN; public double PQTYPLAN { get { return Helper.RoundX(_PQTYPLAN, 1); } set { _PQTYPLAN = value; } }

        private double _PACTPLAN; public double PACTPLAN { get { if (JobQty == 0)   return 0; return Helper.RoundX(Convert.ToDouble(100 * QTYACT / JobQty), 1); } set { _PACTPLAN = value; } }
        private double _PMACTPLAN;

        public double PMACTPLAN
        {
            get { if (MQTYPLAN == 0)   return 0; return Helper.RoundX(Convert.ToDouble(100 * MQTYUSED / MQTYPLAN), 1); }
            set { _PMACTPLAN = value; }
        }

        private string _CR; public string CR { get { return _CR; } set { _CR = value; } }
        private string _CG; public string CG { get { return _CG; } set { _CG = value; } }
        private string _CB; public string CB { get { return _CB; } set { _CB = value; } }

        public bool IsStart = false;
        public bool IsEnd = false;

        public JobBase() : base()
        {
            PLANDATE = new ITXDateTime();
            ACTDATE = new ITXDateTime();
        }

        public virtual void SetUp()
        {
            JobFace();
            ColorDef();
            FlowSteps();
            Dates();
        }

        public virtual void JobFace()
        {
            this.Name = JobID;
            JobType = dwJob["JOBTYPE"].ToString();
            string jobname = dwJob["ABFAUFKRS"].ToString()
                    + "-" + Helper.GetSubRollNum(dwJob["ABFAUFLFD"].ToString())
                    + "-" + Helper.GetSubRollNum(dwJob["ABFAUFPOS"].ToString())
                    + "_" + Convert.ToInt16(dwJob["MKFTP"].ToString());
            jobname += "***";
            jobname = jobname.Replace("_0***", "");
            jobname = jobname.Replace("***", "");
            AUF = jobname;
            LFD = Helper.GetSubRollNum(dwJob["ABFAUFLFD"].ToString());
            ART = Helper.GetGB2312Value(dwJob["ABPART"].ToString()).Trim();
            FARBE = Helper.GetGB2312Value(dwJob["ABPFARBE"].ToString()).Trim();
            JobDes = ART + "-" + FARBE;

            if (!PageScope.ContainsKey(Name))
            {
                PageScope.RegisterName(Name, this);
                //PageScope.UnregisterName(Name);
            }
        }

        public ITXDateTime PLANDATE
        {
            get;
            set;
        }

        public ITXDateTime ACTDATE
        {
            get;
            set;
        }
     
        public virtual void FlowSteps()
        {

            if (ABFOLGE == null)
                return;
            if (StepShow == null)
                return;
            try
            {
                Step Step;
                int idx = 0;
                string processedstep = "";
                var qF = (from DataRow row in ABFOLGE.AsEnumerable()
                          select row).Distinct();
                foreach (DataRow dwABFOLGE in qF)
                {
                    Step = new Step();
                    string step = dwABFOLGE["ABFAFOLGE"].ToString();
                    if (processedstep.Contains(step + ";")) continue;
                    processedstep += step + ";";
                    Step.dwABFOLGE = dwABFOLGE;
                    if (KSLEIST != null)
                    {
                        filter = "KSLAFOLGE='" + dwABFOLGE["ABFAFOLGE"].ToString() + "'";
                        sort = "KSLMDAT ASC";
                        DataRow[] rows = KSLEIST.Select(filter, sort);
                        if (rows.Length > 0)
                        {
                            DataTable tb = KSLEIST.Select(filter, sort).CopyToDataTable();
                            tb.TableName = "KSLEIST";
                            Step.KSLEIST = tb;
                        }
                    }
                    Step.SetUp();
                    Step.SetValue(Grid.ColumnProperty, idx);
                    idx++;
                    StepShow.Children.Add(Step);
                }
            }
            catch (Exception ex)
            {
                LogHelper.error(ex.StackTrace + ex.Message);
            }
        }

        private SolidColorBrush _JBrush; public SolidColorBrush JBrush { get { return _JBrush; } set { _JBrush = value; } }
        Border JBorder
        {
            get
            {
                return (Border)this.FindName("border");
            }
        }

        public int StartPoint
        {
            get;
            set;
        }

        public int GRIDS
        {
            get;
            set;
        }

        public double PIXELS
        {
            get
            {
                return MGANTT.PIXELS;
            }
        }

        public TAV13 PR01
        {
            get
            {
                return this.FindName("P01") as TAV13;
            }
        }

        public TAV13 PR02
        {
            get
            {
                return this.FindName("P02") as TAV13;
            }
        }

        public TAV13 PR03
        {
            get
            {
                return this.FindName("P03") as TAV13;
            }
        }

        public TAV13 PR04
        {
            get
            {
                return this.FindName("P04") as TAV13;
            }
        }

        public Grid MasterGrid
        {
            get
            {
                return (this.FindName("MGrid")) as Grid;
            }
        }

        public void PositionJob(UIAM m)
        { 
            Machine = m;
            if (MGANTT != null)
            {
                if (MGANTT.MainGrid.Children.Contains(this))
                {
                    MGANTT.MainGrid.Children.Remove(this);
                }
            }

            SetColumns();
            if (PR01 != null)
            {
                PR01.Start = this.CalendarStart;
                PR01.AWIDTH = AWIDTH;
                PR01.GetCalendarPosition(PLANDATE);
            }
            if (PR02 != null)
            {
                PR01.Start = this.CalendarStart;
                PR01.AWIDTH = AWIDTH;
                PR02.GetCalendarPosition(ACTDATE);
            }
            StartPoint = MCALENDAR.GetPosition(StartDate); ;
            Expand();
            double MJNUM = Convert.ToDouble(Machine.MJNUM);
            double MJQTY = Convert.ToDouble(Machine.MJQTY);
            Machine.MJNUM = (MJNUM + 1).ToString();
            MJQTY = MJQTY + Convert.ToDouble(JobQty);
            Machine.MJQTY = MJQTY.ToString();
            SetPosition();
            MGANTT.MainGrid.Children.Add(this); 
        }

        public void SetColumns()
        {
            ColumnDefinition cd;
            int TotalBlocks = Convert.ToInt16(Math.Round(MinPixes / PIXELS));
            for (int i = 0; i < TotalBlocks; i++)
            {
                cd = new ColumnDefinition();
                cd.Width = new GridLength(PIXELS);
                MasterGrid.ColumnDefinitions.Add(cd);
            }
        }

        public void Expand()
        {
            ColumnDefinition cd;
            int TotalBlocks = Convert.ToInt16(Math.Round(MinPixes / PIXELS));
            if (PR01 == null)
                return;

            if (GRIDS < TotalBlocks)
                return;
            for (int i = 0; i < GRIDS - TotalBlocks; i++)
            {
                cd = new ColumnDefinition();
                cd.Width = new GridLength(PIXELS);
                MasterGrid.ColumnDefinitions.Add(cd);
            }
        }

        private void SetPosition()
        {
            this.SetValue(Grid.RowProperty, 0);
            this.SetValue(Grid.RowSpanProperty, 2);            
            this.SetValue(Grid.ColumnProperty, StartPoint);
            int RelativeStart = 0;

            if (PR01 != null)
            {
                RelativeStart = PR01.StartPoint - StartPoint;
                if (RelativeStart < 0)
                    RelativeStart = 0;
                PR01.SetValue(Grid.ColumnProperty, RelativeStart);
                PR01.SetValue(Grid.ColumnSpanProperty, PR01.GRIDS);
            }
            if (PR02 != null)
            {
                RelativeStart = PR02.StartPoint - StartPoint;
                if (RelativeStart < 0)
                    RelativeStart = 0;
                PR02.SetValue(Grid.ColumnProperty, RelativeStart);
                PR02.SetValue(Grid.ColumnSpanProperty, PR02.GRIDS);
            }
            if (GRIDS * MGANTT.PIXELS < MinPixes)
            {
                GRIDS = Convert.ToInt16(Math.Round(MinPixes / MGANTT.PIXELS));
                this.SetValue(Grid.ColumnSpanProperty, GRIDS);
            }
            else
            {
                this.SetValue(Grid.ColumnSpanProperty, GRIDS);
            }
            if (JobType == "X")
            {
                this.Visibility = Visibility.Collapsed;
            }
            AWIDTH = GRIDS * MGANTT.PIXELS;
        }

        public void LOADABF()
        {
            if (!IsABF)
                return;
            if (ABFOLGE != null)
                return;
            DataRow dwData = VABFOLGE.Instance.SetProd.Tables["ABFOLGE"].NewRow();
            dwData["ABFMANDANT"] = app.Mandant;
            dwData["ABFAUFKRS"] = dwJob["ABFAUFKRS"];
            dwData["ABFAUFLFD"] = dwJob["ABFAUFLFD"];
            dwData["ABFAUFPOS"] = dwJob["ABFAUFPOS"];
            SResult = VABFOLGE.Instance.QueryABFOLGE(dwData, 1);
            ABFOLGE = SResult.Tables[0].Copy();

        }

        public void LOADKSL()
        {
            if (!IsKSL)
                return;
            if (KSLEIST != null)
                return;
            DataRow dwData = VABFOLGE.Instance.SetProd.Tables["KSLEIST"].NewRow();
            dwData["KSLMANDANT"] = app.Mandant;
            dwData["KSLAUFKRS"] = dwJob["ABFAUFKRS"];
            dwData["KSLAUFLFD"] = dwJob["ABFAUFLFD"];
            dwData["KSLAUFPOS"] = dwJob["ABFAUFPOS"];
            SResult = VKSLEIST.Instance.QueryKSLEIST(dwData, 4);
            KSLEIST = SResult.Tables[0].Copy();
        }

        public virtual void Dates()
        {
            if (dwJob["MKFERLKZ"].ToString().Trim().Length > 0)
                IsEnd = true;

            switch (JobType)
            {
                case "P"://生产   
                case "C":
                case "S"://排产和固定排产
                case "X"://停工维护不更新设备的完成时间，但是开始和结束时间的时候，要定位遇到的障碍，如果跨越，如何表达：直接把时间加到本加工任务上，然后表明有维修？
                default:
                    //MKFPLDATV，MKFPLTIME，ENDATE，ENDTIME
                    PLANDATE.StartDate = dwJob["MKFPLDATV"].ToString();
                    PLANDATE.StartTime = dwJob["MKFPLTIME"].ToString();
                    PLANDATE.EndDate = dwJob["ENDATE"].ToString();
                    PLANDATE.EndTime = dwJob["ENDTIME"].ToString();

                    PLANDATE.ProcessTime = Convert.ToDouble(dwJob["ABFAMASCHZT"].ToString());
                    if (dwJob["ABFISTARTDAT"].ToString().Trim() == "0")
                        IsStart = false;
                    else
                        IsStart = true;
                    if (!IsStart)
                    {
                        ACTDATE.StartDate = "0";
                        ACTDATE.EndDate = "0";
                        break;
                    }
                    ACTDATE.ProcessTime = Convert.ToDouble(dwJob["ABFAMASCHZT"].ToString());
                    ACTDATE.StartDate = dwJob["ABFISTARTDAT"].ToString();
                    ACTDATE.StartTime = dwJob["ABFISTARTZT"].ToString();
                    ACTDATE.EndDate = dwJob["ABFIENDDAT"].ToString();
                    ACTDATE.EndTime = dwJob["ABFIENDZT"].ToString();
                    //ABFISTARTDAT,ABFISTARTZT,ABFIENDDAT,ABFIENDZT
                    if (!IsEnd)
                    {
                        DateTime m_date = ACTDATE.StartDateTime.AddMinutes(ACTDATE.ProcessTime);
                        string enddate = "0", endtime = "0";
                        Helper.GetStdDate(ref enddate, ref endtime, m_date);
                        ACTDATE.EndDate = enddate;
                        ACTDATE.EndTime = endtime;
                        ACTDATE.EndDateTime = m_date;
                        dwJob["ABFIENDDAT"] = enddate;
                        dwJob["ABFIENDZT"] = endtime;
                    }
                    break;
            }
            int t1 = DateTime.Compare(PLANDATE.StartDateTime, ACTDATE.StartDateTime);
            int t2 = DateTime.Compare(PLANDATE.EndDateTime, ACTDATE.EndDateTime);
            if (t1 >= 0)
            {
                StartDate = ACTDATE.StartDateTime;
                if (ACTDATE.StartDate == "0")
                {
                    StartDate = PLANDATE.StartDateTime;
                }
            }
            else
            {
                StartDate = PLANDATE.StartDateTime;
            }
            if (t2 >= 0)
            {
                EndDate = PLANDATE.EndDateTime;

            }
            else
            {
                EndDate = ACTDATE.EndDateTime;
            }
            GRIDS = Convert.ToInt32(EndDate.Subtract(StartDate).TotalHours + 1);
            if (GRIDS < 24)
                GRIDS = 24;
            if (GRIDS > 24 * 60)
                GRIDS = 24 * 60;
            if (PR01 != null)
            {
                PR01.SetUp();
            }
            if (PR02 != null)
            {
                PR02.SetUp();
            }
        }

        public virtual void ColorDef()
        {
            CR = dwJob["CR"].ToString();
            CG = dwJob["CG"].ToString();
            CB = dwJob["CB"].ToString();
            JBrush = new SolidColorBrush();
            if (CR == "000" && CG == "000" && CB == "000")
            {
                Random random = new Random();
                CR = random.Next(0, 255).ToString();
                CG = random.Next(0, 255).ToString();
                CB = random.Next(0, 255).ToString();
            }
            byte cr = Convert.ToByte(CR);
            byte cg = Convert.ToByte(CG);
            byte cb = Convert.ToByte(CB);

            JBrush.Color = Color.FromRgb(cr, cg, cb);
            JBorder.BorderBrush = JBrush;
        }
    }
    */
}
